package com.softeem.blog.dao;

import java.util.List;

import com.softeem.blog.entity.Tag;
import com.softeem.blog.utils.DBUtils;

public class TagDAO implements IBaseDAO<Tag>{

	@Override
	public boolean insert(Tag t) {
		String sql = "insert into tag(tname) values(?)";
		return DBUtils.exeUpdate(sql, t.getTname());
	}

	@Override
	public boolean deleteById(int id) {
		String sql = "delete from tag where id=?";
		return DBUtils.exeUpdate(sql, id);
	}

	@Override
	public boolean update(Tag t) {
		String sql = "update tag set tname=? where id=?";
		return DBUtils.exeUpdate(sql, t.getTname(),t.getId());
	}

	@Override
	public Tag findById(int id) {
		String sql = "select * from tag where id=?";
		return DBUtils.queryOne(Tag.class, sql, id);
	}

	@Override
	public List<Tag> findByPage(int pageSize, int pageNow) {
		String sql = "select * from tag limit ?,?";
		return DBUtils.queryList(Tag.class, sql, (pageNow-1)*pageSize,pageSize);
	}

	@Override
	public int getCount() {
		String sql = "select count(*) from tag";
		return DBUtils.queryCount(sql);
	}

	public Tag findByTname(String tname) {
		String sql = "select * from tag where tname=?";
		return DBUtils.queryOne(Tag.class, sql, tname);
	}

}
